package 力扣日常刷题.木22二月.第01天206;

/**
 * @author 帅小伙
 * @date 2022/2/6
 * @description
 */
public class Demo17JZ礼物的最大价值 {

    public int maxValue(int[][] grid) {
        int n = grid.length, m = grid[0].length;
        int[] dp = new int[m];

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                dp[j] = (j == 0) ? dp[j] + grid[i][j] : Math.max(dp[j - 1],dp[j]) + grid[i][j];
            }
        }
        return dp[m - 1];
    }

}
